#include<iostream>
using namespace std;
//多态：电脑组装的实现
#include<iostream>
using namespace std;

//抽象的CPU类
class CPU
{
public:
	//抽象的计算函数
	virtual void calculate()=0;
};

//抽象的GPU类
class GPU
{
public:
	//抽象的显示函数
	virtual void display() = 0;
};

//抽象的内存条类
class Memory
{
public:
	//抽象的存储函数
	virtual void storage() = 0;
};

//电脑类
class Computer
{
public:
	Computer(CPU* cpu, GPU* gpu,Memory* mem)
	{
		m_cpu=cpu;
		m_gpu = gpu;
		m_mem = mem;
	}

	void doWork()
	{
		m_cpu->calculate();
		m_gpu->display();
		m_mem->storage();
	}

	~Computer()
	{
		//释放CPU
		if (m_cpu != NULL)
		{
			delete m_cpu;
			m_cpu = NULL;
		}
		
		//释放显卡
		if (m_gpu != NULL)
		{
			delete m_gpu;
			m_gpu = NULL;
		}

		//释放内存条
		if (m_mem != NULL)
		{
			delete m_mem;
			m_mem = NULL;
		}
	}
private:
	CPU* m_cpu;
	GPU* m_gpu;
	Memory* m_mem;
};

//intel
class IntelCPU :public CPU
{
public:
	//重写父类函数
	virtual void calculate()
	{
		cout << "intel的CPU开始计算" << endl;
	}
};

class IntelGPU :public GPU
{
public:
	virtual void display()
	{
		cout << "intel的GPU开始计算了" << endl;
	}
};

class IntelMemory :public Memory
{
public:
	virtual void storage()
	{
		cout << "intel的内存条开始存储了" << endl;
	}
};

//Lenovo
class LenovoCPU :public CPU
{
public:
	virtual void calculate()
	{
		cout << "Lenovo的CPU开始计算" << endl;
	}
};

class LenovoGPU :public GPU
{
public:
	virtual void display()
	{
		cout << "Lenovo的GPU开始计算了" << endl;
	}
};

class LenovoMemory :public Memory
{
public:
	virtual void storage()
	{
		cout << "Lenovo的内存条开始存储了" << endl;
	}
};

void test01()
{
	cout << "第一胎电脑：" << endl;
//第一台电脑组装
	//第一台电脑零件
	CPU* intelCPU = new IntelCPU;
	GPU* intelGPU = new IntelGPU;
	Memory* intelMem = new IntelMemory;

	//第一台电脑
	Computer* Computer1 = new Computer(intelCPU,intelGPU,intelMem);
	Computer1->doWork();
	delete Computer1;

	
	cout << "---------------------" << endl;
	cout << "第二台电脑：" << endl;
	//第 二台电脑组装
	Computer* Computer2 = new Computer(new LenovoCPU, new LenovoGPU, new LenovoMemory);
	Computer2->doWork();
	delete Computer2;

	cout << "---------------------" << endl;
	cout << "第三台电脑：" << endl;
	//第 二台电脑组装
	Computer* Computer3 = new Computer(new LenovoCPU, new IntelGPU, new LenovoMemory);
	Computer3->doWork();
	delete Computer3;
}
int main()
{
	test01();
	return 0;
}